using System.Collections.Generic;
using PetShop.BusinessEntities;
using PetShop.DataAccess.DAO;

namespace PetShop.BusinessEntityManagers
{
    public class ItemBO
    {
        public int CurrentQuantityInStock(string itemId)
        {
            if (itemId.Trim() == string.Empty)
                return 0;
            var dal = new ItemDAO();
            return dal.CurrentQtyInStock(itemId);
        }


        public bool IsThereEnoughInStock(string itemId, int cartItemQuantity)
        {
            int unitsInStock = CurrentQuantityInStock(itemId);
            int unitInStockprevision = unitsInStock - cartItemQuantity;
            bool enoughInStock = unitInStockprevision >= 0;
            return enoughInStock;
        }


        public void TakeStock(InventoryItemInfo[] items)
        {
            var dalc = new ItemDAO();
            dalc.TakeStock(items);
        }

        public List<ItemInfo> GetItemsByProduct(string productId)
        {
            if (string.IsNullOrEmpty(productId))
                return null;
            var dal = new ItemDAO();
            List<ItemInfo> dalGetItemsByProduct = dal.GetItemsByProduct(productId);
            return dalGetItemsByProduct;
        }


        public ItemInfo GetItem(string itemId)
        {
            if (string.IsNullOrEmpty(itemId))
                return null;
            var dal = new ItemDAO();
            ItemInfo dalGetItem = dal.GetItem(itemId);
            return dalGetItem;
        }
    }
}